package main.java.com.lx.tools.utils

import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil
import com.intellij.ui.IdeBorderFactory
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTextField


class UIUtil {
    companion object {

        /**在对话框面中
         * 添加一个数据框的内容
         */
        fun addTextInputToPanel(label: String, dataKey: String, panel: JPanel): JTextField {
            panel.add(JLabel(label), ExternalSystemUiUtil.getFillLineConstraints(0))
            val textField = getTextField(PlatformUtil.getData(dataKey, ""))
            panel.add(textField, ExternalSystemUiUtil.getFillLineConstraints(0))
            return textField
        }

        fun addTextInputToPanel(label: String, panel: JPanel): JTextField {
            panel.add(JLabel(label), ExternalSystemUiUtil.getFillLineConstraints(0))
            val textField = getTextField("")
            panel.add(textField, ExternalSystemUiUtil.getFillLineConstraints(0))
            return textField
        }

        /**
         * 创建一个文本输入框
         */
        private fun getTextField(defaultStr: String): JTextField {
            val jTextField = JTextField(defaultStr, 25)
            jTextField.border = IdeBorderFactory.createEmptyBorder(4, 4, 4, 4)
            return jTextField
        }

    }


}